package people.paper.tv.activity.home.modual.rmrb.view.impl;

import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.skyworth.ui.newrecycleview.NewRecycleAdapterItem;
import com.skyworth.util.Util;

import people.paper.tv.R;
import people.paper.tv.activity.home.modual.rmrb.view.data.DailyData;
import people.paper.tv.activity.home.modual.rmrb.view.data.DateListData;
import people.paper.tv.utils.ui.MarqueeTextView;

public class DatePickItemView extends FrameLayout implements NewRecycleAdapterItem<DateListData> {
    FrameLayout contentLayout;
    MarqueeTextView title;
    DateListData mdata;
    int curPosition;

    public DatePickItemView(@NonNull Context context) {
        super(context);

        setFocusable(true);
        setFocusableInTouchMode(true);

        contentLayout = new FrameLayout(context);
        addView(contentLayout, new LayoutParams(Util.Div(394), Util.Div(120)));

        title = new MarqueeTextView(context);
        title.setTextSize(Util.Dpi(36));
        title.setTextColor(getResources().getColor(R.color.title_unfocus));
        LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL);
        params.leftMargin = Util.Div(60);
        contentLayout.addView(title, params);
    }

    @Override
    public View getView() {
        return this;
    }

    @Override
    public void onUpdateData(DateListData data, int position) {
        this.mdata = data;
        curPosition = position;
        if (data == null) {
            return;
        }
    }

    @Override
    public void clearItem() {

    }

    @Override
    public void refreshUI() {
        if (mdata != null) {
            Log.i("rmrb", "DailyData DailyItemView:"+mdata.date);
            title.setText(mdata.date);
            onFocusChange(hasFocus());
        }
    }

    public void onClickAction() {
        if(mdata != null)
            mdata.onClick.run();
    }

    public void onFocusChange(boolean hasFocus) {
        if(hasFocus){
            setBackgroundColor(getResources().getColor(R.color.content_selected_bg));
            title.setTextColor(getResources().getColor(R.color.title_focus));
        }else {
            if(mdata.isCurSelected){
                setBackground(null);
                title.setTextColor(getResources().getColor(R.color.title_selected));
            }else {
                setBackground(null);
                title.setTextColor(getResources().getColor(R.color.title_unfocus));
            }
        }
    }

    @Override
    public void destroy() {

    }
}
